package com.example.positioning.Task;

import com.alibaba.fastjson.JSONObject;
import com.example.positioning.service.AfterWebSocket;
import javafx.geometry.Point2D;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.awt.*;

@Component
public class WebSocketTask {
    @Autowired
    private AfterWebSocket afterWebSocket;
    public Point2D point=null;
    private Point2D last=new Point2D(114.404926,30.52621);
    public boolean inroom=false;

    @Scheduled(cron = "0/1 * * * * ?")
    private void sendTask(){
        JSONObject json=new JSONObject();
        if(point==null)
        {
            json.put("x",last.getX());
            json.put("y",last.getY());
        }
        else {
            json.put("x",point.getX());
            json.put("y",point.getY());
            last=point;
            point=null;
        }
        json.put("inroom",inroom);
        afterWebSocket.sendMessage(json.toString());
    }
}
